<script setup>
import { ref } from 'vue';
import NurseService from './components/NurseService.vue';
import StrokeRehab from './components/StrokeRehab.vue';
import TCMCare from './components/TCMCare.vue';
import MedicalAccompany from './components/MedicalAccompany.vue';
import VitalSigns from './components/VitalSigns.vue';
import BedriddingCare from './components/BedriddingCare.vue';
import AppointmentPage from './components/AppointmentPage.vue';
import MyPage from './components/MyPage.vue';

const currentView = ref('home');
const selectedService = ref('');
const currentTab = ref('home');
const appointmentParams = ref({});

const showServiceDetail = (service) => {
  selectedService.value = service;
  currentView.value = service;
};

const goBackToHome = () => {
  currentView.value = 'home';
};

const showAppointment = (params) => {
  appointmentParams.value = params || {};
  currentView.value = 'appointment';
};

const switchTab = (tab) => {
  currentTab.value = tab;
  if (tab === 'home') {
    currentView.value = 'home';
  } else if (tab === 'my') {
    currentView.value = 'my';
  } else {
    // 其他标签页的处理逻辑
  }
};
</script>

<template>
  <div class="app-container">
    <main>
      <div v-if="currentView === 'home'">
        <NurseService @select-service="showServiceDetail" @show-appointment="showAppointment" />
      </div>
      <div v-else-if="currentView === 'stroke-rehab'">
        <StrokeRehab @go-back="goBackToHome" @show-appointment="showAppointment" />
      </div>
      <div v-else-if="currentView === 'tcm-care'">
        <TCMCare @go-back="goBackToHome" @show-appointment="showAppointment" />
      </div>
      <div v-else-if="currentView === 'medical-accompany'">
        <MedicalAccompany @go-back="goBackToHome" @show-appointment="showAppointment" />
      </div>
      <div v-else-if="currentView === 'vital-signs'">
        <VitalSigns @go-back="goBackToHome" @show-appointment="showAppointment" />
      </div>
      <div v-else-if="currentView === 'bedridden-care'">
        <BedriddingCare @go-back="goBackToHome" @show-appointment="showAppointment" />
      </div>
      <div v-else-if="currentView === 'appointment'">
        <AppointmentPage @go-back="goBackToHome" :params="appointmentParams" />
      </div>
      <div v-else-if="currentView === 'my'">
        <MyPage />
      </div>
    </main>
    
    <!-- 底部导航栏 -->
    <div class="bottom-nav">
      <div class="nav-item" :class="{ active: currentTab === 'home' }" @click="switchTab('home')">
        <div class="nav-icon">🏠</div>
        <div class="nav-text">首页</div>
      </div>
      <div class="nav-item" :class="{ active: currentTab === 'category' }" @click="switchTab('category')">
        <div class="nav-icon">📋</div>
        <div class="nav-text">分类</div>
      </div>
      <div class="nav-item" :class="{ active: currentTab === 'ask' }" @click="switchTab('ask')">
        <div class="nav-icon">💬</div>
        <div class="nav-text">问问我</div>
      </div>
      <!-- <div class="nav-item" :class="{ active: currentTab === 'discount' }" @click="switchTab('discount')">
        <div class="nav-icon">🏷️</div>
        <div class="nav-text">低价购</div>
      </div> -->
      <div class="nav-item" :class="{ active: currentTab === 'my' }" @click="switchTab('my')">
        <div class="nav-icon">👤</div>
        <div class="nav-text">我的</div>
      </div>
    </div>
    
    <!-- 底部占位，防止内容被底部固定栏遮挡 -->
    <div class="bottom-placeholder"></div>
  </div>
</template>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100vw;
  max-width: 100vw;
  overflow-x: hidden;
  position: relative;
  margin: 0;
  padding: 0;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: #f5f5f5;
  color: #333;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app-container {
  width: 100vw;
  max-width: 100vw;
  margin: 0;
  padding: 0;
  position: relative;
  overflow-x: hidden;
}

header {
  text-align: center;
  padding: 15px 0;
  background-color: #00a163;
  color: white;
  width: 100%; /* 确保宽度为100% */
}

header h1 {
  font-size: 1.5rem;
  margin: 0;
}

main {
  background-color: #ffffff;
  width: 100vw;
  min-height: calc(100vh - 110px);
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

footer {
  text-align: center;
  padding: 15px 0;
  background-color: #f8f8f8;
  color: #666;
  font-size: 0.875rem;
  border-top: 1px solid #eaeaea;
  width: 100%; /* 确保宽度为100% */
}

button {
  background-color: #00a163;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1rem;
  transition: background-color 0.3s;
  -webkit-tap-highlight-color: transparent;
}

button:hover {
  background-color: #008c55;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* 底部导航栏 */
.bottom-nav {
  display: flex;
  background-color: white;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  margin: 0 auto;
  z-index: 100;
  width: 100%; /* 确保宽度为100% */
  box-sizing: border-box;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #999;
  padding: 8px 0;
  -webkit-tap-highlight-color: transparent;
}

.nav-icon {
  font-size: 24px;
  margin-bottom: 2px;
}

.nav-text {
  font-size: 12px;
}

.nav-item.active {
  color: #00a163;
}

.bottom-placeholder {
  height: 60px;
  width: 100%;
}

/* 移动端适配 */
@media screen and (max-width: 768px) {
  html {
    font-size: 14px;
  }
  
  .app-container {
    padding: 0;
    width: 100%;
  }
  
  button {
    padding: 8px 16px;
  }
}

/* 禁止水平滚动 */
html, body {
  overflow-x: hidden;
  position: relative;
  width: 100%;
  max-width: 100%;
}

/* 修复iOS Safari中的滚动问题 */
@supports (-webkit-overflow-scrolling: touch) {
  body {
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100%;
  }
}
</style>
